package com.taiyuan.tongcheng.adapter;

import java.util.ArrayList;
import java.util.List;

import org.kymjs.kjframe.ui.ViewInject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.tytc56.user.R;

public class CarKindAdapter extends BaseAdapter {
	private LayoutInflater layoutInflater;
	private Context context;
	public static final String[] carName = new String[] { "加长面包车", "3.3米封闭厢式货车",
			"4.2米封闭厢式货车" };
	//ccc111222
	public static final int[] carId=new int[]{1,2,3};
	private List<String > carList=new ArrayList<String>();
	private int[] carLableSelcted = new int[] {
			R.drawable.icon_trucktype_0_active,
			R.drawable.icon_trucktype_1_active,
			R.drawable.icon_trucktype_2_active };
	private int[] carLableNomal = new int[] {
			R.drawable.icon_trucktype_0_default,
			R.drawable.icon_trucktype_1_default,
			R.drawable.icon_trucktype_2_default };
	

	private int selectPosition= 0;

	public CarKindAdapter(Context context) {
		this.context = context;
		this.layoutInflater = LayoutInflater.from(context);
		for (int i = 0; i < carName.length; i++) {
			carList.add(carName[i]);
		}
	}

	public int getSelecPosition() {

		if(selectPosition==666){
			return 0;
		}else{
			return carId[selectPosition];
		}
	
	}

	public void setSlectPositon(int postion) {
		
		 if(postion != selectPosition){
		      this.selectPosition = postion;
		       notifyDataSetChanged();
		 }
	}

	public int getCount() {
		return carList.size();
	}

	public Object getItem(int position) {
		return carList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ZuJian zuJian = null;
		if (convertView == null) {
			zuJian = new ZuJian();
			convertView = layoutInflater.inflate(R.layout.list_item_carstyle,
					null);
			zuJian.lableImageView = (ImageView) convertView
					.findViewById(R.id.img_car_lable);
			zuJian.stateImageView = (ImageView) convertView
					.findViewById(R.id.img_car_state);
			zuJian.infoView = (TextView) convertView
					.findViewById(R.id.tv_car_name);
			convertView.setTag(zuJian);
		} else {
			zuJian = (ZuJian) convertView.getTag();
		}

		zuJian.infoView.setText(carName[position]);
		if (position == selectPosition) {
			zuJian.lableImageView.setImageResource(carLableSelcted[position]);
			zuJian.stateImageView
					.setImageResource(R.drawable.icon_car_radio_active);
			zuJian.infoView.setTextColor(context.getResources().getColor(
					R.color.tcps_color_car_selected));
		} else {
			zuJian.lableImageView.setImageResource(carLableNomal[position]);
			zuJian.infoView.setTextColor(context.getResources().getColor(
					R.color.tcps_color_car_normal));
			zuJian.stateImageView
					.setImageResource(R.drawable.icon_car_radio_default);

		}
		return convertView;
	}

	public final class ZuJian {
		public TextView infoView;
		public ImageView lableImageView;
		public ImageView stateImageView;
	}

}